package Thread.day01;

/**
 * 3个窗口卖票，总共100张，使用实现Runable接口的方法
 * 仍存在线程安全问题
 */
public class Exer3 {
    public static void main(String[] args) {
        window1 w1 = new window1();
        Thread t1 = new Thread(w1);
        Thread t2 = new Thread(w1);
        Thread t3 = new Thread(w1);
        t1.setName("窗口1");
        t2.setName("窗口2");
        t3.setName("窗口3");
        t1.start();
        t2.start();
        t3.start();
    }

}
class window1 implements Runnable{
    private  int ticket = 100;
    @Override
    public void run() {
        while(true){
            if (ticket>0){
                System.out.println(Thread.currentThread().getName()+"卖了票号为"+ticket);
                ticket--;
            }else{
              break;
        }
    }

    }
}
